<?php
	class FileUploadView{
		
		private $UploadSubmit = 'upload';
		private $UploadTypes = array("image/gif", "image/jpeg");
		
		/**
		 * Returnerar XHTMl för filuppladdningsformulär
		 * @return string med xhtml
		 *
		 * @TODO Strängberoenden
		 */
		public function DoUploadForm(){
			return "
				<form method='post' enctype='multipart/form-data'>
					<fieldset>
						<legend>Ladda upp fil</legend>
						<label for='file'>Filnamn: </label>
						<input type='file' name='file' id='file' />
						<br />
						<input type='submit' name='$this->UploadSubmit' value='Ladda upp'>
					</fieldset>
				</form>
			";
		}
		
		/**
		 * Visar alla filer
		 * @return array med filnamn
		 */
		public function ShowFiles($files){
			$folder = "upload/";		
			
			$xhtml = "<h3>Filer</h3>";
			$xhtml .= "<ul>";
			foreach ($files as $key => $value) {
				$xhtml .= "<li>";
				$xhtml .= "<a href='$folder$value' rel='lightbox' title='$value'>$value</a>";
				$xhtml .= "</li>";	
			}
			$xhtml .= "</ul>";
			return $xhtml;
		}
		
		public function uploadSucceeded(){
			return "<p>Uppladdning lyckades!</p>";
		}
		
		public function uploadFailed(){
			return "<p>Uppladdning misslyckades! Filerna kan max vara 10MB samt endast vara av formaten jpg, jpeg och gif</p>";
		}
		
		public function TriedToUpload(){	
			// Returnera true eller false
			if (isset($_POST[$this->UploadSubmit]) == TRUE) {
				return TRUE;				
			} else {
				return FALSE;
			}
		}
		
		public function HasFile(){
			if(isset($_FILES['file']) == TRUE){
				return TRUE;
			}else {
				return FALSE;
			}
		}
		
		public function GetFileInfo(){
			if(isset($_FILES['file']) == TRUE){
				return $_FILES['file'];
			}
		}
		
		/*
		 * $TODO Strängberoenden
		 */
		public function GetFile(){
			if (isset($_FILES['file']) == TRUE) {
				return $_FILES['file'];
			}
		}
	}

				